//
//  meetingViewController.m
//  诗韵
//
//  Created by Song on 2018/3/8.
//  Copyright © 2018年 Song. All rights reserved.
//

#import "meetingViewController.h"

@interface meetingViewController ()
@property (weak, nonatomic) IBOutlet UILabel *count;
- (IBAction)back:(id)sender;

//创建定时器(因为下面两个方法都使用,所以定时器拿出来设置为一个属性)
@property(nonatomic,weak) NSTimer *countDownTimer;

@end

@implementation meetingViewController

static NSInteger secondsCountDown = 10;

-(void)viewWillDisappear:(BOOL)animated {
    [_countDownTimer setFireDate:[NSDate distantFuture]];
    _countDownTimer = nil;
}

-(void)viewWillAppear:(BOOL)animated {
    secondsCountDown = 10;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置定时器
    _countDownTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDownAction) userInfo:nil repeats:YES];
    self.count.text = @"10秒";
}

//实现倒计时动作
-(void)countDownAction{
    if (secondsCountDown <= 0) {
        self.count.text = @"时间到！";
    }else {
        //倒计时-1
        secondsCountDown--;
        self.count.text = [NSString stringWithFormat:@"%ld秒",(long)secondsCountDown];
        NSLog(@" = %ld",secondsCountDown);
    }
}

- (IBAction)back:(id)sender {
    [self dismissViewControllerAnimated:YES completion:^{
        NSLog(@"移除");
    }];
}
@end
